#install packages
#install.packages("gtrendsR", quietly = TRUE, warn.conflicts = FALSE)
#install.packages ("dplyr", quietly = TRUE, warn.conflicts = FALSE)
#install.packages ("ggplot2", quietly = TRUE, warn.conflicts = FALSE)
#install.packages ("tibble")
#install.packages("tidyverse")


########################################
###  Salience of the commemoration   ###
###   Code: Francesco Colombo        ###
########################################
rm(list = ls())


library(dplyr, quietly = TRUE, warn.conflicts = FALSE)
library(ggplot2, quietly = TRUE, warn.conflicts = FALSE)
library(gtrendsR, quietly = TRUE, warn.conflicts = FALSE)
library(ggthemes, quietly = TRUE, warn.conflicts = FALSE)
library(tibble)
library(tidyverse)

################# 2020 ################
liberazione <- gtrends(c("liberazione"), geo = c("IT", "IT"), time = c("2020-03-25 2020-05-25"))
partigiani <- gtrends(c("partigiani"), geo = c("IT", "IT"), time = c("2020-03-25 2020-05-25"))
mussolini <- gtrends(c("mussolini"), geo = c("IT", "IT"), time = c("2020-03-25 2020-05-25"))
nazifascismo <- gtrends(c("nazifascismo"), geo = c("IT", "IT"), time = c("2020-03-25 2020-05-25"))


time_trend_liberazione<-liberazione$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_liberazione <- rename(time_trend_liberazione, liberazione.hits = hits)
time_trend_liberazione <- rename(time_trend_liberazione, liberazione.keyword =  keyword)
time_trend_liberazione <- time_trend_liberazione[!duplicated(time_trend_liberazione$date), ]


time_trend_partigiani<-partigiani$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_partigiani <- rename(time_trend_partigiani, partigiani.hits = hits)
time_trend_partigiani <- rename(time_trend_partigiani, partigiani.keyword =  keyword)
time_trend_partigiani <- time_trend_partigiani[!duplicated(time_trend_partigiani$date), ]

time_trend_mussolini<-mussolini$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_mussolini <- rename(time_trend_mussolini, mussolini.hits = hits)
time_trend_mussolini <- rename(time_trend_mussolini, mussolini.keyword =  keyword)
time_trend_mussolini <- time_trend_mussolini[!duplicated(time_trend_mussolini$date), ]

time_trend_nazifascismo<-nazifascismo$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_nazifascismo <- rename(time_trend_nazifascismo, nazifascismo.hits = hits)
time_trend_nazifascismo <- rename(time_trend_nazifascismo, nazifascismo.keyword =  keyword)
time_trend_nazifascismo <- time_trend_nazifascismo[!duplicated(time_trend_nazifascismo$date), ]

time_trend <- left_join(time_trend_liberazione, time_trend_partigiani, by = "date")
time_trend <- left_join(time_trend, time_trend_nazifascismo, by = "date")
time_trend <- left_join(time_trend, time_trend_mussolini, by = "date")


##### PLOT

plot2020 <- ggplot(data=time_trend, aes(x=date))+
  geom_line(aes(y=liberazione.hits, color="liberazione"), size=1, linetype = "solid") +
  geom_line(aes(y=nazifascismo.hits, color="nazifascismo"), size=1, linetype = "solid") +
  geom_line(aes(y=partigiani.hits, color="partigiani"), size=1, linetype = "solid") +
   geom_line(aes(y=mussolini.hits, color="mussolini"), size=1, linetype = "solid") +
 xlab('Time')+
  ylab('Relative Interest')+ 
  ggtitle("") + 
  geom_vline(xintercept=as.Date("2020-04-25"), colour="black", size=1.2) +
  geom_text(aes(x=as.Date("2020-04-25"), label="Treatment", y=90), colour="black", angle=90, vjust = 1.2, text=element_text(size=20))+
  geom_vline(xintercept=as.Date("2020-04-11"), colour="black", size=1.2) +
  geom_text(aes(x=as.Date("2020-04-11"), label="Control", y=90), colour="black", angle=90, vjust = 1.2, text=element_text(size=20))+
  scale_color_manual(name = "Word searched", 
                     values = c("brown", "grey", "red", "lightblue" ), 
                     labels = c("nazifascismo",  "mussolini" , "partigiani", "liberazione")) + 
  theme_fivethirtyeight()

plot2020 <- plot2020 + theme(legend.title = element_text(size=16))
plot2020 <- plot2020 + theme(legend.text = element_text(size=14))
                 
plot2020

ggsave( 
  "trends_2020.pdf",
  plot = plot2020,
  path = "C:/Users/Francesco/OneDrive - Istituto Universitario Europeo/EUI/paper/25th_of_april/pap/graphs",
  scale = 1)

################# 2019 ################
liberazione <- gtrends(c("liberazione"), geo = c("IT", "IT"), time = c("2019-03-25 2019-05-25"))
partigiani <- gtrends(c("partigiani"), geo = c("IT", "IT"), time = c("2019-03-25 2019-05-25"))
mussolini <- gtrends(c("mussolini"), geo = c("IT", "IT"), time = c("2019-03-25 2019-05-25"))
nazifascismo <- gtrends(c("nazifascismo"), geo = c("IT", "IT"), time = c("2019-03-25 2019-05-25"))


time_trend_liberazione<-liberazione$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_liberazione <- rename(time_trend_liberazione, liberazione.hits = hits)
time_trend_liberazione <- rename(time_trend_liberazione, liberazione.keyword =  keyword)
time_trend_liberazione <- time_trend_liberazione[!duplicated(time_trend_liberazione$date), ]


time_trend_partigiani<-partigiani$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_partigiani <- rename(time_trend_partigiani, partigiani.hits = hits)
time_trend_partigiani <- rename(time_trend_partigiani, partigiani.keyword =  keyword)
time_trend_partigiani <- time_trend_partigiani[!duplicated(time_trend_partigiani$date), ]

time_trend_mussolini<-mussolini$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_mussolini <- rename(time_trend_mussolini, mussolini.hits = hits)
time_trend_mussolini <- rename(time_trend_mussolini, mussolini.keyword =  keyword)
time_trend_mussolini <- time_trend_mussolini[!duplicated(time_trend_mussolini$date), ]

time_trend_nazifascismo<-nazifascismo$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_nazifascismo <- rename(time_trend_nazifascismo, nazifascismo.hits = hits)
time_trend_nazifascismo <- rename(time_trend_nazifascismo, nazifascismo.keyword =  keyword)
time_trend_nazifascismo <- time_trend_nazifascismo[!duplicated(time_trend_nazifascismo$date), ]

time_trend <- left_join(time_trend_liberazione, time_trend_partigiani, by = "date")
time_trend <- left_join(time_trend, time_trend_nazifascismo, by = "date")
time_trend <- left_join(time_trend, time_trend_mussolini, by = "date")



##### PLOT

plot2019 <- ggplot(data=time_trend, aes(x=date))+
  geom_line(aes(y=liberazione.hits, color="liberazione"), size=1, linetype = "solid") +
  geom_line(aes(y=partigiani.hits, color="partigiani"), size=1, linetype = "solid") +
  geom_line(aes(y=mussolini.hits, color="mussolini"), size=1, linetype = "solid") +
  geom_line(aes(y=nazifascismo.hits, color="nazifascismo"), size=1, linetype = "solid") +
  xlab('Time')+
  ylab('Relative Interest')+ 
  ggtitle("") + 
  geom_vline(xintercept=as.Date("2019-04-25"), colour="black", size=1.2) +
  geom_text(aes(x=as.Date("2019-04-25"), label="Treatment", y=90), colour="black", angle=90, vjust = 1.2, text=element_text(size=20))+
  geom_vline(xintercept=as.Date("2019-04-11"), colour="black", size=1.2) +
  geom_text(aes(x=as.Date("2019-04-11"), label="Control", y=90), colour="black", angle=90, vjust = 1.2, text=element_text(size=20))+
  scale_color_manual(name = "Word searched", 
                     values = c("brown", "grey", "red", "lightblue" ), 
                     labels = c("nazifascismo",  "mussolini" , "partigiani", "liberazione")) + 
  theme_fivethirtyeight()

plot2019 <- plot2019 + theme(legend.title = element_text(size=16))
plot2019 <- plot2019 + theme(legend.text = element_text(size=14))

plot2019

ggsave( 
  "trends_2019.pdf",
  plot = plot2019,
  path = "C:/Users/Francesco/OneDrive - Istituto Universitario Europeo/EUI/paper/25th_of_april/pap/graphs",
  scale = 1)

################# 2018 ################
liberazione <- gtrends(c("liberazione"), geo = c("IT", "IT"), time = c("2018-03-25 2018-05-25"))
partigiani <- gtrends(c("partigiani"), geo = c("IT", "IT"), time = c("2018-03-25 2018-05-25"))
mussolini <- gtrends(c("mussolini"), geo = c("IT", "IT"), time = c("2018-03-25 2018-05-25"))
nazifascismo <- gtrends(c("nazifascismo"), geo = c("IT", "IT"), time = c("2018-03-25 2018-05-25"))


time_trend_liberazione<-liberazione$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_liberazione <- rename(time_trend_liberazione, liberazione.hits = hits)
time_trend_liberazione <- rename(time_trend_liberazione, liberazione.keyword =  keyword)
time_trend_liberazione <- time_trend_liberazione[!duplicated(time_trend_liberazione$date), ]


time_trend_partigiani<-partigiani$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_partigiani <- rename(time_trend_partigiani, partigiani.hits = hits)
time_trend_partigiani <- rename(time_trend_partigiani, partigiani.keyword =  keyword)
time_trend_partigiani <- time_trend_partigiani[!duplicated(time_trend_partigiani$date), ]

time_trend_mussolini<-mussolini$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_mussolini <- rename(time_trend_mussolini, mussolini.hits = hits)
time_trend_mussolini <- rename(time_trend_mussolini, mussolini.keyword =  keyword)
time_trend_mussolini <- time_trend_mussolini[!duplicated(time_trend_mussolini$date), ]

time_trend_nazifascismo<-nazifascismo$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_nazifascismo <- rename(time_trend_nazifascismo, nazifascismo.hits = hits)
time_trend_nazifascismo <- rename(time_trend_nazifascismo, nazifascismo.keyword =  keyword)
time_trend_nazifascismo <- time_trend_nazifascismo[!duplicated(time_trend_nazifascismo$date), ]

time_trend <- left_join(time_trend_liberazione, time_trend_partigiani, by = "date")
time_trend <- left_join(time_trend, time_trend_nazifascismo, by = "date")
time_trend <- left_join(time_trend, time_trend_mussolini, by = "date")



##### PLOT
plot2018 <- ggplot(data=time_trend, aes(x=date))+
  geom_line(aes(y=liberazione.hits, color="liberazione"), size=1, linetype = "solid") +
  geom_line(aes(y=partigiani.hits, color="partigiani"), size=1, linetype = "solid") +
  geom_line(aes(y=mussolini.hits, color="mussolini"), size=1, linetype = "solid") +
  geom_line(aes(y=nazifascismo.hits, color="nazifascismo"), size=1, linetype = "solid") +
  xlab('Time')+
  ylab('Relative Interest')+ 
  ggtitle("") + 
  geom_vline(xintercept=as.Date("2018-04-25"), colour="black", size=1.2) +
  geom_text(aes(x=as.Date("2018-04-25"), label="Treatment", y=90), colour="black", angle=90, vjust = 1.2, text=element_text(size=20))+
  geom_vline(xintercept=as.Date("2018-04-11"), colour="black", size=1.2) +
  geom_text(aes(x=as.Date("2018-04-11"), label="Control", y=90), colour="black", angle=90, vjust = 1.2, text=element_text(size=20))+
  scale_color_manual(name = "Word searched", 
                     values = c("brown", "grey", "red", "lightblue" ), 
                     labels = c("nazifascismo",  "mussolini" , "partigiani", "liberazione")) + 
  theme_fivethirtyeight()

plot2018 <- plot2018 + theme(legend.title = element_text(size=16))
plot2018 <- plot2018 + theme(legend.text = element_text(size=14))

plot2018


ggsave( 
  "trends_2018.pdf",
  plot = plot2018,
  path = "C:/Users/Francesco/OneDrive - Istituto Universitario Europeo/EUI/paper/25th_of_april/pap/graphs",
  scale = 1)

################# 2017 ################
liberazione <- gtrends(c("liberazione"), geo = c("IT", "IT"), time = c("2017-03-25 2017-05-25"))
partigiani <- gtrends(c("partigiani"), geo = c("IT", "IT"), time = c("2017-03-25 2017-05-25"))
mussolini <- gtrends(c("mussolini"), geo = c("IT", "IT"), time = c("2017-03-25 2017-05-25"))
nazifascismo <- gtrends(c("nazifascismo"), geo = c("IT", "IT"), time = c("2017-03-25 2017-05-25"))


time_trend_liberazione<-liberazione$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_liberazione <- rename(time_trend_liberazione, liberazione.hits = hits)
time_trend_liberazione <- rename(time_trend_liberazione, liberazione.keyword =  keyword)
time_trend_liberazione <- time_trend_liberazione[!duplicated(time_trend_liberazione$date), ]


time_trend_partigiani<-partigiani$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_partigiani <- rename(time_trend_partigiani, partigiani.hits = hits)
time_trend_partigiani <- rename(time_trend_partigiani, partigiani.keyword =  keyword)
time_trend_partigiani <- time_trend_partigiani[!duplicated(time_trend_partigiani$date), ]

time_trend_mussolini<-mussolini$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_mussolini <- rename(time_trend_mussolini, mussolini.hits = hits)
time_trend_mussolini <- rename(time_trend_mussolini, mussolini.keyword =  keyword)
time_trend_mussolini <- time_trend_mussolini[!duplicated(time_trend_mussolini$date), ]

time_trend_nazifascismo<-nazifascismo$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_nazifascismo <- rename(time_trend_nazifascismo, nazifascismo.hits = hits)
time_trend_nazifascismo <- rename(time_trend_nazifascismo, nazifascismo.keyword =  keyword)
time_trend_nazifascismo <- time_trend_nazifascismo[!duplicated(time_trend_nazifascismo$date), ]

time_trend <- left_join(time_trend_liberazione, time_trend_partigiani, by = "date")
time_trend <- left_join(time_trend, time_trend_nazifascismo, by = "date")
time_trend <- left_join(time_trend, time_trend_mussolini, by = "date")

##### PLOT

plot2017 <- ggplot(data=time_trend, aes(x=date))+
  geom_line(aes(y=liberazione.hits, color="liberazione"), size=1, linetype = "solid") +
  geom_line(aes(y=partigiani.hits, color="partigiani"), size=1, linetype = "solid") +
  geom_line(aes(y=mussolini.hits, color="mussolini"), size=1, linetype = "solid") +
  geom_line(aes(y=nazifascismo.hits, color="nazifascismo"), size=1, linetype = "solid") +
  xlab('Time')+
  ylab('Relative Interest')+ 
  ggtitle("") + 
  geom_vline(xintercept=as.Date("2017-04-25"), colour="black", size=1.2) +
  geom_text(aes(x=as.Date("2017-04-25"), label="Treatment", y=90), colour="black", angle=90, vjust = 1.2, text=element_text(size=20))+
  geom_vline(xintercept=as.Date("2017-04-11"), colour="black", size=1.2) +
  geom_text(aes(x=as.Date("2017-04-11"), label="Control", y=90), colour="black", angle=90, vjust = 1.2, text=element_text(size=20))+
  scale_color_manual(name = "Word searched", 
                     values = c("brown", "grey", "red", "lightblue" ), 
                     labels = c("nazifascismo",  "mussolini" , "partigiani", "liberazione")) + 
  theme_fivethirtyeight()

plot2017 <- plot2017 + theme(legend.title = element_text(size=16))
plot2017 <- plot2017 + theme(legend.text = element_text(size=14))
plot2017

ggsave( 
  "trends_2017.pdf",
  plot = plot2017,
  path = "C:/Users/Francesco/OneDrive - Istituto Universitario Europeo/EUI/paper/25th_of_april/pap/graphs",
  scale = 1)

  
################# 2016 ################
liberazione <- gtrends(c("liberazione"), geo = c("IT", "IT"), time = c("2016-03-25 2016-05-25"))
partigiani <- gtrends(c("partigiani"), geo = c("IT", "IT"), time = c("2016-03-25 2016-05-25"))
mussolini <- gtrends(c("mussolini"), geo = c("IT", "IT"), time = c("2016-03-25 2016-05-25"))
nazifascismo <- gtrends(c("nazifascismo"), geo = c("IT", "IT"), time = c("2016-03-25 2016-05-25"))


time_trend_liberazione<-liberazione$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_liberazione <- rename(time_trend_liberazione, liberazione.hits = hits)
time_trend_liberazione <- rename(time_trend_liberazione, liberazione.keyword =  keyword)
time_trend_liberazione <- time_trend_liberazione[!duplicated(time_trend_liberazione$date), ]


time_trend_partigiani<-partigiani$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_partigiani <- rename(time_trend_partigiani, partigiani.hits = hits)
time_trend_partigiani <- rename(time_trend_partigiani, partigiani.keyword =  keyword)
time_trend_partigiani <- time_trend_partigiani[!duplicated(time_trend_partigiani$date), ]

time_trend_mussolini<-mussolini$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_mussolini <- rename(time_trend_mussolini, mussolini.hits = hits)
time_trend_mussolini <- rename(time_trend_mussolini, mussolini.keyword =  keyword)
time_trend_mussolini <- time_trend_mussolini[!duplicated(time_trend_mussolini$date), ]

time_trend_nazifascismo<-nazifascismo$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_nazifascismo <- rename(time_trend_nazifascismo, nazifascismo.hits = hits)
time_trend_nazifascismo <- rename(time_trend_nazifascismo, nazifascismo.keyword =  keyword)
time_trend_nazifascismo <- time_trend_nazifascismo[!duplicated(time_trend_nazifascismo$date), ]

time_trend <- left_join(time_trend_liberazione, time_trend_partigiani, by = "date")
time_trend <- left_join(time_trend, time_trend_nazifascismo, by = "date")
time_trend <- left_join(time_trend, time_trend_mussolini, by = "date")

##### PLOT

plot2016 <- ggplot(data=time_trend, aes(x=date))+
  geom_line(aes(y=liberazione.hits, color="liberazione"), size=1, linetype = "solid") +
  geom_line(aes(y=partigiani.hits, color="partigiani"), size=1, linetype = "solid") +
  geom_line(aes(y=mussolini.hits, color="mussolini"), size=1, linetype = "solid") +
  geom_line(aes(y=nazifascismo.hits, color="nazifascismo"), size=1, linetype = "solid") +
  xlab('Time')+
  ylab('Relative Interest')+ 
  ggtitle("") + 
  geom_vline(xintercept=as.Date("2016-04-25"), colour="black", size=1.2) +
  geom_text(aes(x=as.Date("2016-04-25"), label="Treatment", y=90), colour="black", angle=90, vjust = 1.2, text=element_text(size=20))+
  geom_vline(xintercept=as.Date("2016-04-11"), colour="black", size=1.2) +
  geom_text(aes(x=as.Date("2016-04-11"), label="Control", y=90), colour="black", angle=90, vjust = 1.2, text=element_text(size=20))+
  scale_color_manual(name = "Word searched", 
                     values = c("brown", "grey", "red", "lightblue" ), 
                     labels = c("nazifascismo",  "mussolini" , "partigiani", "liberazione")) + 
  theme_fivethirtyeight()

plot2016 <- plot2016 + theme(legend.title = element_text(size=16))
plot2016 <- plot2016 + theme(legend.text = element_text(size=14))
plot2016

ggsave( 
  "trends_2016.pdf",
  plot = plot2016,
  path = "C:/Users/Francesco/OneDrive - Istituto Universitario Europeo/EUI/paper/25th_of_april/pap/graphs",
  scale = 1)
  
  
################# 2015 ################
liberazione <- gtrends(c("liberazione"), geo = c("IT", "IT"), time = c("2015-03-25 2015-05-25"))
partigiani <- gtrends(c("partigiani"), geo = c("IT", "IT"), time = c("2015-03-25 2015-05-25"))
mussolini <- gtrends(c("mussolini"), geo = c("IT", "IT"), time = c("2015-03-25 2015-05-25"))
nazifascismo <- gtrends(c("nazifascismo"), geo = c("IT", "IT"), time = c("2015-03-25 2015-05-25"))


time_trend_liberazione<-liberazione$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_liberazione <- rename(time_trend_liberazione, liberazione.hits = hits)
time_trend_liberazione <- rename(time_trend_liberazione, liberazione.keyword =  keyword)
time_trend_liberazione <- time_trend_liberazione[!duplicated(time_trend_liberazione$date), ]


time_trend_partigiani<-partigiani$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_partigiani <- rename(time_trend_partigiani, partigiani.hits = hits)
time_trend_partigiani <- rename(time_trend_partigiani, partigiani.keyword =  keyword)
time_trend_partigiani <- time_trend_partigiani[!duplicated(time_trend_partigiani$date), ]

time_trend_mussolini<-mussolini$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_mussolini <- rename(time_trend_mussolini, mussolini.hits = hits)
time_trend_mussolini <- rename(time_trend_mussolini, mussolini.keyword =  keyword)
time_trend_mussolini <- time_trend_mussolini[!duplicated(time_trend_mussolini$date), ]

time_trend_nazifascismo<-nazifascismo$interest_over_time %>%
  dplyr::mutate(hits=ifelse(hits=="<1",0.5,as.numeric(hits)),
                date=as.Date(date))
time_trend_nazifascismo <- rename(time_trend_nazifascismo, nazifascismo.hits = hits)
time_trend_nazifascismo <- rename(time_trend_nazifascismo, nazifascismo.keyword =  keyword)
time_trend_nazifascismo <- time_trend_nazifascismo[!duplicated(time_trend_nazifascismo$date), ]

time_trend <- left_join(time_trend_liberazione, time_trend_partigiani, by = "date")
time_trend <- left_join(time_trend, time_trend_nazifascismo, by = "date")
time_trend <- left_join(time_trend, time_trend_mussolini, by = "date")

##### PLOT

plot2015 <- ggplot(data=time_trend, aes(x=date))+
  geom_line(aes(y=liberazione.hits, color="liberazione"), size=1, linetype = "solid") +
  geom_line(aes(y=partigiani.hits, color="partigiani"), size=1, linetype = "solid") +
  geom_line(aes(y=mussolini.hits, color="mussolini"), size=1, linetype = "solid") +
  geom_line(aes(y=nazifascismo.hits, color="nazifascismo"), size=1, linetype = "solid") +
  xlab('Time')+
  ylab('Relative Interest')+ 
  ggtitle("") + 
  geom_vline(xintercept=as.Date("2015-04-25"), colour="black", size=1.2) +
  geom_text(aes(x=as.Date("2015-04-25"), label="Treatment", y=90), colour="black", angle=90, vjust = 1.2, text=element_text(size=20))+
  geom_vline(xintercept=as.Date("2015-04-11"), colour="black", size=1.2) +
  geom_text(aes(x=as.Date("2015-04-11"), label="Control", y=90), colour="black", angle=90, vjust = 1.2, text=element_text(size=20))+
  scale_color_manual(name = "Word searched", 
                     values = c("brown", "grey", "red", "lightblue" ), 
                     labels = c("nazifascismo",  "mussolini" , "partigiani", "liberazione")) + 
  theme_fivethirtyeight()

plot2015 <- plot2015 + theme(legend.title = element_text(size=16))
plot2015 <- plot2015 + theme(legend.text = element_text(size=14))

plot2015

ggsave( 
  "trends_2015.pdf",
  plot = plot2015,
  path = "C:/Users/Francesco/OneDrive - Istituto Universitario Europeo/EUI/paper/25th_of_april/pap/graphs",
  scale = 1)
